/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.cmoine.perspectiveshare.importWizards;

import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;


public class PerspectiveShareImportWizardPage extends WizardPage {
	
	protected FileFieldEditor editor;
    protected String filePath;

	public PerspectiveShareImportWizardPage(String pageName, IStructuredSelection selection) {
        super(pageName);
        setTitle(pageName);
        setDescription(Messages.pageDescription);
	}

    public void createControl(Composite parent) {
        Composite fileSelectionArea=new Composite(parent, SWT.NONE);
        GridData fileSelectionData=new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
        fileSelectionArea.setLayoutData(fileSelectionData);

        GridLayout fileSelectionLayout=new GridLayout();
        fileSelectionLayout.numColumns=3;
        fileSelectionLayout.makeColumnsEqualWidth=false;
        fileSelectionLayout.marginWidth=0;
        fileSelectionLayout.marginHeight=0;
        fileSelectionArea.setLayout(fileSelectionLayout);

        editor=new FileFieldEditor("fileSelect", "Select File: ", fileSelectionArea); //$NON-NLS-1$ //$NON-NLS-2$
        editor.getTextControl(fileSelectionArea).addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                filePath=PerspectiveShareImportWizardPage.this.editor.getStringValue();
            }
        });
        String[] extensions=new String[] { "*.epf", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
        editor.setFileExtensions(extensions);
        fileSelectionArea.moveAbove(null);

        setControl(fileSelectionArea);
    }

    public String getFilePath() {
        return filePath;
    }
}
